package weather.gui;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import weather.gui.panels.SplitMainPanel;




@SuppressWarnings("serial")
public class MainFrame extends javax.swing.JFrame {
	private JMenuBar mainMenuBar;
	private JMenu helpMenuItem;
	private SplitMainPanel splitPanel;
	private JMenuItem aboutMenuItem;
	private JMenuItem exitMenuItem;
	private JMenu jMenu1;
	private static final String title = "JM Weather";
	private Image im;
	private static final String about = "          JM Weather 2009. \n" +
			                            "              Written by \n" +
			                            "Marian Szczykulski & Jerzy Mazurek";

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				MainFrame inst = new MainFrame();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public MainFrame() {
		super();
		initGUI();
		exitMenuItem.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent arg0) 
			{
				System.exit(0);
				
			}
		});
		aboutMenuItem.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent arg0) 
			{
				JOptionPane.showInternalMessageDialog(MainFrame.this.getContentPane(), about, "JM Weather - information", JOptionPane.INFORMATION_MESSAGE,new ImageIcon(im) );
				
			}
		});

	}
	private void setFrameSize()
	{
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		Dimension dim = toolkit.getScreenSize();
		int hScreen = dim.height;
		int wScreen = dim.width;
		
		setSize(wScreen / 2, hScreen / 2);
		setLocation(wScreen / 4, hScreen / 4);
		
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			im = Toolkit.getDefaultToolkit().getImage("resources\\icon.PNG");
		    this.setIconImage(im);
		    this.setTitle(title);
		    
			{
				splitPanel = new SplitMainPanel();
				getContentPane().add(splitPanel, BorderLayout.CENTER);
			}
			{
				mainMenuBar = new JMenuBar();
				setJMenuBar(mainMenuBar);
				{
					jMenu1 = new JMenu();
					mainMenuBar.add(jMenu1);
					jMenu1.setText("File");
					{
						exitMenuItem = new JMenuItem();
						jMenu1.add(exitMenuItem);
						exitMenuItem.setText("Exit");
					}
				}
				{
					helpMenuItem = new JMenu();
					mainMenuBar.add(helpMenuItem);
					helpMenuItem.setText("Help");
					{
						aboutMenuItem = new JMenuItem();
						helpMenuItem.add(aboutMenuItem);
						aboutMenuItem.setText("About");
					}
				}
			}

			pack();
			this.setFrameSize();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
